<template>
  <scroll-view
    @scrolltolower="handlerTolower"
    class="recommend_view"
    scroll-y
    v-if="recommends.length > 0"
  >
    <!-- 推荐 -->
    <view class="recommend_wrap">
      <navigator
        class="recommend_item"
        v-for="item in recommends"
        :key="item.id"
        :url="`/pages/album/index?id=${item.target}`"
      >
        <img mode="widthFix" :src="item.thumb" alt="" />
      </navigator>
    </view>
    <!-- 月份 -->
    <view class="monthes_wrap">
      <view class="moneth_title">
        <view class="monthes_title_info">
          <view class="monthes_info">
            <text>{{ monthes.DD }} /</text>{{ monthes.MM }}月
          </view>
          <view class="monthes_text">{{ monthes.title }}</view>
        </view>
        <view class="monthes_title_more">更多></view>
      </view>

      <view class="moneth_content">
        <view
          class="moneth_item"
          v-for="(item, index) in monthes.items"
          :key="item.id"
        >
          <go-detail :list="monthes.items" :index="index">
            <img
              mode="aspectFill"
              :src="item.thumb + item.rule.replace('$<Height>', 360)"
              alt=""
            />
          </go-detail>
        </view>
      </view>
    </view>
    <!-- 热门 -->
    <view class="hots_wrap">
      <view class="hots_title">
        <text>热门</text>
      </view>
      <view class="hots_content">
        <view class="hot_item" v-for="(item, index) in hots" :key="item.id">
          <go-detail :list="hots" :index="index">
            <img :src="item.thumb" alt="" />
          </go-detail>
        </view>
      </view>
    </view>
  </scroll-view>
</template>

<script>
import Moment from "moment";
import goDetail from "@/components/goDetail";
export default {
  components: {
    goDetail,
  },
  data() {
    return {
      recommends: [],
      monthes: {},
      hots: [],
      params: {
        limit: 30,
        order: "hot",
        skip: 0,
      },
      hasMore: true,
    };
  },
  mounted() {
    uni.setNavigationBarTitle({ title: "推荐" });

    this.getList();
  },
  methods: {
    handlerTolower() {
      //console.log("到底了");
      if (this.hasMore) {
        this.params.skip += this.params.limit;
        this.getList();
      } else {
        uni.showToast({
          title: "没有更多了",
          icon: "none",
        });
      }
    },
    async getList() {
      const res = await this.request(
        "/image/v3/homepage/vertical",
        this.params,
      );
      if (res.code === 0) {
        if (this.recommends.length === 0) {
          this.recommends = res.res.homepage[1].items;
          this.monthes = res.res.homepage[2];
          //Moment.js
          this.monthes.MM = Moment(this.monthes.stime).format("MM");
          this.monthes.DD = Moment(this.monthes.stime).format("DD");
        }
        if (res.res.vertical.length === 0) {
          this.hasMore = false;
          return;
        }
        this.hots = [...this.hots, ...res.res.vertical];
      }
    },
  },
};
</script>

<style lang="scss">
.recommend_wrap {
  display: flex;
  flex-wrap: wrap;
  .recommend_item {
    flex: 50%;
    border: 5rpx solid #fff;
  }
}
.monthes_wrap {
  .moneth_title {
    display: flex;
    justify-content: space-between;
    padding: 20rpx;
    .monthes_title_info {
      color: $color;
      font-weight: 600;
      font-size: 30rpx;
      display: flex;
      .monthes_info {
        text {
          font-size: 36rpx;
        }
      }

      .monthes_text {
        font-size: 34rpx;
        color: #666;
        margin-left: 30rpx;
      }
    }

    .monthes_title_more {
      font-size: 24rpx;
      color: $color;
    }
  }

  .moneth_content {
    display: flex;
    flex-wrap: wrap;
    .moneth_item {
      flex: 33.333333%;
    }
  }
}
.hots_wrap {
  .hots_title {
    padding: 20rpx;
    text {
      border-left: 20rpx solid $color;
      padding-left: 20rpx;
      font-size: 34rpx;
      font-weight: 600;
    }
  }
  .hots_content {
    display: flex;
    flex-wrap: wrap;
    .hot_item {
      flex: 33.3333%;
    }
  }
}
.recommend_view {
  //height:等于屏幕高度-头部标题高度
  height: calc(100vh - 36px);
}
</style>
